package com.example.zm_fanjiantao.web.controller;

import com.example.zm_fanjiantao.utils.Result;
import com.example.zm_fanjiantao.web.model.User;
import com.example.zm_fanjiantao.web.service.RestfulUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RequestMapping("/restfull/user")
@RestController
public class RestfulUserController {


    private static final Logger log = LoggerFactory.getLogger(RestfulUserController.class);

    @Resource
    private RestfulUserService restfulUserService;

    @GetMapping
    public Result<List<User>> list(){
        log.info("查询用户信息");
        return Result.success(restfulUserService.userList());
    }
    @PostMapping
    public Result<User> save(@RequestBody User user){
         user.setCreate_date(new Date());
         restfulUserService.save(user);
         return Result.success(user);
    }

    @PutMapping
    public User update(@RequestBody User user){
        restfulUserService.update(user);
        return user;
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable int id){
         restfulUserService.delete(id);
    }
    @GetMapping("/{id}")
    public User findUser(@PathVariable int id){
        return restfulUserService.findUser(id);
    }

}
